﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class frmupdategoods : Form
    {
        public frmupdategoods()
        {
            InitializeComponent();
        }
        public int stu1;
        string strconn = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        private void frmupdategoods_Load(object sender, EventArgs e)
        {
            dzh();
        }
        public void dzh()
        {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            string sql = "select slId,slLei from [Commodity type] where slId='" + stu1 + "'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                    tbxleibie.Text = reader["slId"].ToString();
                tbxmingc.Text = reader["slLei"].ToString();
            }
        }

        private void buttonsave_Click(object sender, EventArgs e)
        {
              SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            int bianhao = Convert.ToInt32(this.tbxleibie.Text);
            string dj = this.tbxmingc.Text;
            string sql = "update [Commodity type] set slId='" + bianhao + "',slLei='" + dj + "' where slId='"+stu1+"'";
            SqlCommand cmd = new SqlCommand(sql,conn);
            int i=cmd.ExecuteNonQuery();
            if (i>0)
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
            conn.Close();
        }

        private void buttonquxaio_Click(object sender, EventArgs e)
        {
            this.Close();
        }  
        }
    }

